home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 14 / MacFormat n. 14 (Spain) / MacFormat 14.bin / Shareware Internet / Educación / xComputer 1.2.1 / Examples / Example 1 - Basics next >
Encoding:
Text File  |  1995-12-28  |  4.9 KB  |  97 lines

  1. ; Example 1:  Basics
  2.  
  3. ; This file contains a fairly simple program written in the
  4. ; assembly language of xComputer.  It illustrates a few basic
  5. ; assembly language instructions and the format of assembly
  6. ; language programs.  (Note that a semicolon (;) and anthing
  7. ; that follows it on a line is a comment.)
  8.  
  9. ; This and other example files illustrate the functionality
  10. ; of xComputer.  They do not tell you everything you need to
  11. ; know to use the xComputer program.  For that, you should read
  12. ; the file "READ ME (with instructions!)".  That file also
  13. ; includes a complete specification of the assembly language
  14. ; of xComputer.
  15.  
  16. ; To run this program, open it with the xComputer program.
  17. ; Make sure the program is in the frontmost window on the
  18. ; screen.  Choose the command "Load Example 1 - Basics" from
  19. ; the Assembler menu.  Make sure that the PC register contains
  20. ; the number 0, which gives the starting address of the program
  21. ; in memory.  (Use the "Set PC=0" command from the Assembler
  22. ; menu, if necessary.)  Then use the Run command from the
  23. ; Assembly menu to start the program, or, equivalently,
  24. ; click on the checkbox labled "Stop-Clock" in the xComputer
  25. ; window.
  26.  
  27. ; This program computes the sum of a list of numbers.  The list
  28. ; can contain only non-zero numbers.  A zero marks the end of
  29. ; the list.
  30.  
  31.  
  32.  
  33.        lod-c 0        ; Load the constant 0 into the AC; this
  34.                       ;     will be the starting value of the sum.
  35.        sto sum        ; Store the contents of the AC into
  36.                       ;    location "sum".  "Sum" is a label
  37.                       ;    that is used to refer to some memory
  38.                       ;    location.  (It is defined later in the
  39.                       ;    program by using it to label one of
  40.                       ;    the lines in the program.)
  41.        lod-c numList  ; Load the constant "numList" into AC
  42.        sto num        ; and then copy it into location "num".
  43.  
  44. doSum: lod-i num      ; "Load-indirect from num", that is, get
  45.                       ;     the contents of location "num", and
  46.                       ;     use THAT number as the location of the
  47.                       ;     number to be loaded into the AC.  In
  48.                       ;     this case, one of the numbers in the
  49.                       ;     list is loaded.  Note that "doSum"
  50.                       ;     is a label for this instruction.
  51.        jmz done       ; If the number in the AC is zero, then
  52.                       ;     jump to location "done".  (The zero
  53.                       ;     marks the end of the list of numbers.)
  54.        add sum        ; Otherwise, add the number in location
  55.                       ;     "sum" to the AC
  56.        sto sum        ; and put the answer back in "sum".
  57.        lod num        ; Now, get the number from "num",
  58.        inc            ; add 1 to it,
  59.        sto num        ; and put the answer back in "num".
  60.                       ;     (This gets us ready to access the
  61.                       ;      next item in the list.)
  62.        jmp doSum      ; Jump back to location "doSum", which
  63.                       ;     is therefore the starting point of
  64.                       ;     a loop.
  65. done:  hlt            ; Halt; the program jumps to this point
  66.                       ;     when the program is done.
  67.  
  68. num:   data           ; Allocate a memory location to hold data
  69.                       ;     and set the label "num" to refer
  70.                       ;     to that memory location.  ("Data" is
  71.                       ;     not an instruction, just a placeholder
  72.                       ;     that tells the assembler to reserve
  73.                       ;     a memory location.) 
  74. sum:   data           ; Allocate a memory location named "sum";
  75.                       ;     This location, which will be location
  76.                       ;     number 14 when the program is loaded,
  77.                       ;     will hold the answer when the 
  78.                       ;     program ends.
  79.  
  80. numList:      ; A label that names the starting point for
  81.               ;   the list of numbers to be added.  (Note that
  82.               ;   a label does not have to be on the same line
  83.               ;   with the item it labels.)
  84.        27     ; The list of numbers to be added.  Note that
  85.        53     ;   when a number is encountered as a line in    
  86.        107    ;   a program, that number is simply loaded
  87.        -22    ;   into a memory location.  Thus, these numbers
  88.        67     ;   will occupy successive memory locations
  89.        -232   ;   starting at location 15.  Of course, the
  90.        123    ;   program will work for any list of numbers.
  91.        1      ;   (Note:  If you load this program and then
  92.        272    ;   set the Memory Display Option to "Assembly
  93.        -13    ;   Language", some of these numbers will look
  94.        -12    ;   sort of funny, since they do not represent
  95.        100    ;   legal assembly language instructions.)
  96.        0      ; A zero marks end of the list of numbers
  97.               ;    to be added.